<template>
	<SkeletonScreen v-if="loading"></SkeletonScreen>
	<!-- 分红记录-->
	<view class="wchat">
		<view class="flex" v-for="item in userValue">
			<view>
				<view>{{item.channel}}</view>
				<view style="color: #969696; font-size: 22rpx;">{{item.time}}</view>
			</view>
			<view v-if="type == 1" style="color: #ff0000;">- {{item.money}} 元</view>
			<view v-if="type ==2" style="color: #ff0000;">+ {{item.money}} 元</view>
		</view>
	</view>
	
	<view style="display: flex; justify-content: center; align-items: center; padding: 30rpx 0; color: #464646;">
		<view> ... مەزمۇن تۈگىدى</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		UserMoney
	} from '@/API/geidApis.js';
	import {
		onLoad
	} from '@dcloudio/uni-app';

	const userValue = ref([]);
	const loading = ref(true)
	const type = ref()
	onLoad((e) => {
		console.log("e:", e)
		type.value = e.type
		if (e.type == 1) {
			watchFunction('/collectionUserMony/list');
			uni.setNavigationBarTitle({
				title: 'نەقلەشتۈرۈش خاتىرىسى'
			});
		} else {
			watchFunction('/collectionUserMonyIncome/list');
			uni.setNavigationBarTitle({
				title: 'كىرىم خاتىرىسى'
			});
		}

	});
	// 提现记录
	const watchFunction = async (url) => {
		let user = uni.getStorageSync("user");
		let res = await UserMoney(url, user.id);
		for (let i = 0; i < res.length; i++) {
			res[i].time = formatTimestamp(res[i].gmtCreate)
		}
		userValue.value = res;
		console.log("观看记录内容：", res);
		loading.value = false
	}

	// 时间码转换
	function formatTimestamp(timestamp) {
		const date = new Date(timestamp);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
		const day = String(date.getDate()).padStart(2, '0');
		const hour = String(date.getHours()).padStart(2, '0');
		const minute = String(date.getMinutes()).padStart(2, '0');

		return `${year}-${month}-${day} ${hour}:${minute}`;
	}
</script>

<style scoped>
	.wchat {
		background: #1d1d1d;
		margin-top: 30rpx;
		width: 92%;
		position: relative;
		left: 4%;
		padding: 10rpx 0 30rpx 0;
		box-sizing: border-box;
		border-radius: 20rpx;
		box-shadow: 0 10rpx 20rpx rgba(255, 0, 0, 0.2);
	}

	.flex {
		padding: 10rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
</style>